package rpc

import (
	"apibe/grpc/roads/go/trydo"
	"context"
	"time"
)

type Server struct{}

func (s *Server) AOP(ctx context.Context, req *RoadsRequest) (*RoadsResponse, error) {
	leave, err := req.leave(req.ReqFunction.Name, req.ReqFunction.Parameter)
	back, err := leave.back(req.ResFunction.Name, req.ResFunction.Parameter)
	return back, err
}

func (m *RoadsRequest) leave(name string, parameter []byte) (*RoadsResponse, error) {
	switch name {
	case "":
		break
	case "AES":
		m.Body = trydo.AESEncrypt(parameter, m.Body)
		break
	}
	return m.http(time.Second * 60)
}

func (m *RoadsResponse) back(name string, parameter []byte) (*RoadsResponse, error) {
	switch name {
	case "":
		break
	case "AES":
		m.Body = trydo.AESDecrypt(parameter, m.Body)
		break
	}
	return m, nil
}
